package com.yg.ssm.hello.ctrl;


import com.yg.ssm.hello.model.DemoModel;
import com.yg.ssm.hello.serv.TempService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/8/25.
 */
@Controller
public class TempController {
    //自动装配
    @Autowired
    private TempService ts;

    public void setTs(TempService ts) {
        this.ts = ts;
    }

    @RequestMapping("/my/query")
    @ResponseBody
    public List<DemoModel> query() {
        System.out.println("TsService is Bool:");
        System.out.println(ts == null);
        List<DemoModel> ld = ts.query();
        System.out.println(ld);
        return ld;
    }
    /**
     * @param date
     * */
    @RequestMapping("/my/add/{date}")
    @ResponseBody
    public String Add(@PathVariable("date") String date, @RequestParam("username") String username, @RequestParam("pass") String pass, HttpServletRequest req, HttpServletResponse rep) {
        System.out.println(username);
        System.out.println(pass);
        return date + ":" + username + ":" + pass;
    }

    @RequestMapping("/my/post")
    @ResponseBody
    public Map PostData(String name, String pass,String path, @RequestBody DemoModel demo){
        System.out.println(name);
        System.out.println(pass);
        Map mp = new HashMap();
        mp.put("abc","abcdefg");

        System.out.println(demo);
        return mp;
    }
}
